/**
 * =================================================================
 * 版权所有 2011-2013 深圳市泰海网络科技服务有限公司，并保留所有权利
 * -----------------------------------------------------------------
 * 这不是一个自由软件！您不能在任何未经允许的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布
 * =================================================================
 */
package com.imoney.payment.web.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.imoney.framework.base.entity.Response;
import com.imoney.framework.base.enums.UserType;
import com.imoney.payment.member.domain.Member;
import com.imoney.payment.member.domain.RegRequest;
import com.imoney.payment.member.enums.Country;
import com.imoney.payment.web.common.PathCode;
import com.imoney.payment.web.service.IMemberService;

/**
 * 类说明：会员管理<br>
 * 
 * <p>
 * 详细描述：会员注册/<br>
 * 
 * </p>
 * 
 * <pre>
 * ——————————————————————————————————————————————————————————————————
 * |		修改人		|		修改时间			|		修改原因
 * ——————————————————————————————————————————————————————————————————
 * |	zengxx 曾宪新	|		2013-6-1		|	
 * ——————————————————————————————————————————————————————————————————
 * </pre>
 * 
 * @author zengxx 曾宪新(Xavier.zeng)
 * 
 *         CreateDate: 2013-6-1
 */
@Controller
@RequestMapping("/memberprod")
public class MemberprodController {

	@Resource
	private IMemberService memberService;

	@RequestMapping(value = { "account/reg/index.htm" })
	public Object register(final Model model, HttpServletRequest request,
			String accName, String country, String checkCode) {
		if (RequestMethod.GET.name().equals(request.getMethod())) {
			return PathCode.REG;
		}

		/**
		 * 验证校验码
		 */

		RegRequest regRequest = new RegRequest(accName, UserType.MBR,
				Country.valueOf(country));
		Response<Member> response = memberService.register(regRequest);
		if (20000 != response.getCode()) {
			return PathCode.REG;
		}

		String url = "redirect:/memberprod/account/regComplete.htm?loginId=";
		return new ModelAndView(url + accName);
	}

	@RequestMapping(value = { "account/regComplete.htm" })
	public Object regComplete(final Model model, HttpServletRequest request,
			String loginId) {
		if (RequestMethod.GET.name().equals(request.getMethod())) {
			return PathCode.REG_NEXT;
		}

		String url = "redirect:/memberprod/account/regSucceed.htm?loginId=";
		return new ModelAndView(url + loginId);
	}

	@RequestMapping(value = { "account/regSucceed.htm" })
	public String regSucceed(final Model model, String loginId) {

		return PathCode.REG_END;
	}

	@RequestMapping(value = { "account/reg/statusCheck.json" })
	@ResponseBody
	public String statusCheck(final Model model, String userName) {
		Member member = memberService.queryMemberById(userName);
		if (null == member) {
			return "{\"stat\":\"ok\",\"info\":{\"accName\":\"13699892701\",\"accStatus\":\"activate\",\"accType\":2,\"country\":\"CN\",\"havanaId\":\"\",\"logonType\":\"MOBILE\",\"nick\":\"\",\"totalLimit\":\"10\"}}";
		}

		return "{\"stat\":\"ok\",\"info\":{\"accName\":\"13699892702\",\"accStatus\":\"login\",\"accType\":2,\"country\":\"CN\",\"havanaId\":\"\",\"logonType\":\"MOBILE\",\"nick\":\"\",\"totalLimit\":\"10\"}}";
	}

	@RequestMapping(value = { "account/reg/checkCode.json" })
	@ResponseBody
	public String checkCode(final Model model, String checkCode) {

		if (true) {
			return "{\"stat\":\"ok\"}";
		}

		return "{\"stat\":\"fail\"}";
	}

}
